package com.wyg.epcommonbase.common.enums;

/**
 * @Author: WangYongGan
 * @Date: 2021/10/29 14:45
 * @Description:
 */
public enum SexEnum {
    MAN("男", 1),
    WOMEN("女", 0),
    UNDEFINE("未知", -1);
    private String sex;
    private int code;

    SexEnum(String sex, int code) {
        this.code = code;
        this.sex = sex;
    }

    public static SexEnum getSexByCode(int code) {
        SexEnum[] sexEnums = values();
        for (SexEnum sexEnum : sexEnums) {
            if (code == sexEnum.code)
                return sexEnum;
        }
        return UNDEFINE;
    }

    public static SexEnum getSexByString(String sex) {
        SexEnum[] sexEnums = values();
        for (SexEnum sexEnum : sexEnums) {
            if (sex.equals(sexEnum.sex))
                return sexEnum;
        }
        return UNDEFINE;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public static void main(String[] args) {
        SexEnum sexEnum = SexEnum.valueOf("MAN");
        System.out.println(sexEnum.sex);
    }
}
